Cleaning up the driver data into a usable state prior to use
In this section I am cleaning the pitstop_data$pit_duration to remove na values, and outliers. ### Filtering Down to Race Pitstops
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.8 21.8 23.4 103.0 26.8 2485.9
pitstop_data <- pitstop_data[pitstop_data$pit_duration <= 150,]
pitstop_duration_Q1 <- quantile(pitstop_data$pit_duration, 0.25, na.rm = TRUE)
pitstop_duration_Q3 <- quantile(pitstop_data$pit_duration, 0.75, na.rm = TRUE)
pitstop_iqr <- pitstop_duration_Q3 - pitstop_duration_Q1 #I could also just do this with pitstop_iqr <- IQR(pitstop_data$pit_duration, na.rm = TRUE)
pitstop_median <- median(pitstop_data$pit_duration, na.rm = TRUE)
summary(pitstop_data$pit_duration)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.80 21.70 23.30 24.28 25.30 93.20
Using the Results I have previously gathered, this section will contain several plots created form the aggregated data points
TeamBoxplot <- ggplot(pitstop_data, aes(x = reorder(team_name, pit_duration, median), y = pit_duration, fill = team_colour)) +
geom_boxplot(alpha = 0.6, outlier.shape = NA) +
geom_jitter(width = 0.2, alpha = 0.3, color = "black") +
coord_flip() +
scale_y_continuous(limits = c(quantile(pitstop_data$pit_duration, 0.02, na.rm = TRUE),
quantile(pitstop_data$pit_duration, 0.97, na.rm = TRUE)),
oob = scales::oob_keep) + #looked up this command
labs(title = "Pit Stop Duration by Team", x = "Team", y = "Pit Stop Duration (s)") +
theme_bw()+
theme(legend.position = "none")+
scale_fill_identity()
ggplotly(TeamBoxplot, width = 1200, height = 700) %>%
layout(autosize = TRUE)AveragesGraph <- ggplot(pitstop_average, aes(x = reorder(driver_label, Mean), y = Mean, fill = team_name))+
geom_col()+
scale_fill_manual(values = setNames(pitstop_average$team_colour, pitstop_average$team_name))+
labs(x = "Name Acronyms", y = "Mean (s)", title = "Averages Plot")+
theme(text = element_text(angle = 45, hjust = 1))
ggplotly(AveragesGraph, width = 1200, height = 700) %>%
layout(autosize = TRUE)